﻿using System.Collections.Generic;
using System.IO;
using System.Xml.Linq;

namespace InitApp
{
    public static class AppGlobal
    {
        private static string m_CurrentDirectory;

        /// <summary>
        /// 程序所有路径
        /// </summary>
        private static string CurrentDirectory
        {
            get
            {
                if (string.IsNullOrEmpty(m_CurrentDirectory))
                {
                    m_CurrentDirectory = Directory.GetCurrentDirectory();
                }
                return m_CurrentDirectory;
            }
        }


        private static XElement m_XMLConfig;
        /// <summary>
        /// 配置文件
        /// </summary>
        public static XElement XMLConfig
        {
            get
            {
                if (m_XMLConfig == null)
                {
                    m_XMLConfig = XElement.Load(CurrentDirectory + "\\System.xml");
                }
                return m_XMLConfig;
            }
        }

        /// <summary>
        /// 数据库连接参数
        /// </summary>
        public static IDictionary<string, string> DataBaseConnection
        {
            get
            {
                var result = new Dictionary<string, string>();
                var root = XMLConfig.Element("Activerecor");
                foreach (XElement item in root.Elements())
                {
                    result.Add(item.Attribute("key").Value, item.Attribute("value").Value);
                }
                return result;
            }
        }
    }
}